package com.shelpe.services.sinbad.dto.semiauto;

import org.apache.commons.lang3.math.NumberUtils;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;

@Data
public class SemiautoPriceModel {
	
	@JsonProperty("price_type")
	private int priceType;
	@JsonProperty("price_value")
	private float priceValue;
	@JsonProperty("option_type")
	private int optionType;
	@JsonProperty("price_extreme")
	private String priceExtreme;
	private int status;
	
	public float pricing(float price){
		int sign = (this.optionType == 1?-1:1);
		
		float newPrice = price;
		if(this.priceType == 1){
			newPrice = (1 + this.priceValue * sign) * newPrice;
		}else if(this.priceType == 2){
			newPrice = newPrice +  this.priceValue * 100 * sign;
		}else{
			newPrice = this.priceValue * 100;
		}
		
		//when raise the price, keep the original price if adjusted price is greater than extreme
		float extreme = NumberUtils.toFloat(this.priceExtreme) * 100;
		if(sign > 0 && (extreme > 0 && newPrice > extreme)){
			newPrice = price;
		}
		//when reduce the price, keep the original price if adjusted price is less than extreme
		if(sign < 0 && (extreme > 0 && newPrice < extreme)){
			newPrice = price;
		}
		return newPrice;
	}
}
